//turret.txt - Simple script for turrets
//Cell 0,1 - Stuff done flag. If both 0, nothing. Otherwise If non-zero, this 
//turret wont attack. If the turret is itself attacked, will set the not-attack setting back to 0.

begincreaturescript;

short i,target;
short last_abil;

body;

beginstate INIT_STATE;
	set_resistance(ME,7,100);
	last_abil = get_current_tick();

	if (gf(71,10) > 0)
		set_attitude(ME,4);

	if (gf(71,17) > 0)
		set_attitude(ME,3);

	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE; 
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
		
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking

	if (target_ok() == FALSE)
		set_state(START_STATE);
		
	if ((get_ran(1,0,100) < 50) && (tick_difference(last_abil,get_current_tick()) > 0) &&
	  (can_see_char(get_target()))) {
		print_named_str(ME,"fires a beam of energy.");
		pc_heard_sound_delay(131,250);						
		run_sparkles_on_char(get_target(),6,8,1);
		run_sparkles_on_char(ME,6,8,1);
		
		if (get_ran(1,0,100) < 50)
			set_char_status(get_target(),1,-5);
			else if (get_ran(1,0,100) < 50)
				set_char_status(get_target(),0,-4);
				else set_char_status(get_target(),7,4);
		last_abil = get_current_tick();
		run_char_animation(2,1,35);	
		end();
		}
		
	do_attack();
	turret_heal();
break;

beginstate TALKING_STATE;
	print_str("Talking: The pylon is a simple organism in a crystal shell. It can't talk.");
break;